package org.jeecg.modules.assets.service.impl;

import com.alibaba.fastjson.util.TypeUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.CommonUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.assets.dto.AssetsApplyDTO;
import org.jeecg.modules.assets.dto.AssetsItemDTO;
import org.jeecg.modules.assets.dto.CompanyDTO;
import org.jeecg.modules.assets.entity.*;
import org.jeecg.modules.assets.mapper.AssetsItemHistoryMapper;
import org.jeecg.modules.assets.mapper.AssetsItemMapper;
import org.jeecg.modules.assets.service.*;
import org.jeecg.modules.assets.vo.ApplyAndReturnItem;
import org.jeecg.modules.assets.vo.ItemVO;
import org.jeecg.modules.job.AssetsJob;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * @Description: 资产明细
 * @Author: jeecg-boot
 * @Date: 2023-12-12
 * @Version: V1.0
 */
@Service
@Slf4j
public class AssetsItemServiceImpl extends ServiceImpl<AssetsItemMapper, AssetsItem> implements IAssetsItemService {


    @Autowired
    private AssetsItemHistoryMapper assetsItemHistoryMapper;
    @Resource
    private AssetsItemMapper assetsItemMapper;
    @Autowired
    private IAssetsCategoryService assetsCategoryService;
    @Autowired
    private IAssetsGroupService assetsGroupService;

    @Autowired
    private IAssetsInfoService assetsInfoService;
    @Autowired
    @Lazy
    private IAssetsApplyItemService assetsApplyItemService;
    @Lazy
    @Autowired
    private IAssetsReturnItemService assetsReturnItemService;
    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;
    @Autowired
    AssetsJob assetsJob;


    /**
     * 修改使用人或所属人
     *
     * @param assetsItem
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void editItem(AssetsItem assetsItem) {
        //获取初始id
        Integer id = assetsItem.getId();
        //获取当前登录用户
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        AssetsItemHistory assetsItemHistory = new AssetsItemHistory();
        assetsItemHistory.setUpdateBy(sysUser.getId());
        assetsItemHistory.setUpdateName(sysUser.getRealname());
        //获取修改前的资产信息
        AssetsItem preAssetsItem = this.getById(id);
        BeanUtils.copyProperties(preAssetsItem, assetsItemHistory);
        assetsItemHistory.setId(null);
        assetsItemHistoryMapper.insert(assetsItemHistory);
        //判断是否要更新分类表数量，
        if (preAssetsItem.getCategory() != null) {
            AssetsCategory oldCategory = assetsCategoryService.getById(preAssetsItem.getCategory());
            oldCategory.setNum(oldCategory.getNum() - 1);
            assetsCategoryService.updateById(oldCategory);
        }
        if (assetsItem.getCategory() != null) {
            Integer newCategory = assetsItem.getCategory();
            AssetsCategory newCategorybEntry = assetsCategoryService.getById(newCategory);
            newCategorybEntry.setNum(newCategorybEntry.getNum() + 1);
            //将旧分类库存数量减1，新分类库存数量加1
            assetsCategoryService.updateById(newCategorybEntry);
        }
        //判断是否更新分组表
        if (preAssetsItem.getGroup() != null) {
            AssetsGroup oldGroup = assetsGroupService.getById(preAssetsItem.getGroup());
            oldGroup.setNum(oldGroup.getNum() - 1);
            assetsGroupService.updateById(oldGroup);
        }
        if (assetsItem.getGroup() != null) {
            AssetsGroup newGroup = assetsGroupService.getById(assetsItem.getGroup());
            newGroup.setNum(newGroup.getNum() + 1);
            assetsGroupService.updateById(newGroup);
        }
        this.updateById(assetsItem);

    }

    @Override
    public IPage<AssetsItemDTO> queryPageListBydept(Page<AssetsItemDTO> page, Integer dept, String company, String assetName) {
        //判断是否由部门复盘

        IPage<AssetsItemDTO> pageList = assetsItemMapper.queryPageListBydept(page, dept, company, assetName);
        return pageList;
    }

    /**
     * 获取所有公司明细
     *
     * @return
     */
    @Override
    public List<String> getAllCompanyCode() {

        return assetsItemMapper.getAllCompanyCode();

    }

    /**
     * 获取用户对应公司
     *
     * @param realname
     * @return
     */
    @Override
    public List<CompanyDTO> getCompanyByUser(String realname) {
        List<CompanyDTO> companyByUser = assetsItemMapper.getCompanyByUser(realname);

        return companyByUser;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveItem(AssetsItem assetsItem) {
        if (assetsItem.getAssetName() == null) {
            return;
        }
        //查询资产信息是否有该资产
        QueryWrapper one1 = new QueryWrapper();
        one1.eq("asset_name", assetsItem.getAssetName());
        AssetsInfo assetsInfo = assetsInfoService.getOne(one1);

        if (assetsInfo == null) {
            assetsInfo = new AssetsInfo();
            assetsInfo.setAssetName(assetsItem.getAssetName());
            assetsInfo.setSpec(assetsItem.getSpec());
            assetsInfo.setCompany(assetsItem.getCompany());
            //设备分组、设备分类
            assetsInfo.setGroupName(assetsItem.getGroupName());
            assetsInfo.setCategory(assetsItem.getCategory());
            assetsInfoService.save(assetsInfo);
        }
        Integer num = assetsItem.getNum();
        for (int i = 0; i < num; i++) {
            //自动生成资产编码，资产编码固定6位，将id替换为后面的新增的序列，并不包含日期
            assetsItem.setApplyStatus(1);
            // 设备数量默认为1
            assetsItem.setNum(1);
            //仓库可用数量加1
            //根据分类id填充分类名称
            assetsItem.setStoreNum(1);
            assetsItem.setId(null);
            this.save(assetsItem);
            String assetCoding = String.format("%06d", assetsItem.getId());
            assetsItem.setAssetCoding(assetCoding);
            this.updateById(assetsItem);
            //新增设备类别和组别数量
            assetsJob.startWron();

        }


    }

    /**
     * 设备删除
     *
     * @param id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deletItem(String id) {
        AssetsItem assetsItem = this.getById(id);
        //更新资产信息对应的数
        QueryWrapper one1 = new QueryWrapper();
        one1.eq("asset_name", assetsItem.getAssetName());
        AssetsInfo assetsInfo = assetsInfoService.getOne(one1);
        //设备外借不允许删除
        if (Objects.equals(0, assetsItem.getApplyStatus())) {
            throw new JeecgBootException("设备外借不允许删除");
        }
        assetsInfoService.updateById(assetsInfo);
        this.removeById(id);
        assetsJob.startWron();

    }

    //根据excel导入资产信息
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String importExcel(HttpServletRequest request, HttpServletResponse response) {
        int count = 0;
        StringBuilder builder = new StringBuilder();
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile file = entity.getValue();
            ImportParams params = new ImportParams();
            params.setTitleRows(2);
            params.setHeadRows(1);
            params.setNeedSave(true);
            try {
                List<AssetsInfo> list = ExcelImportUtil.importExcel(file.getInputStream(), AssetsInfo.class, params);
                builder.append("本次共导入：[" + list.size() + "]");
                for (AssetsInfo assetsItem : list) {
                    //插入资产明细
                    saveItemIm(assetsItem);
                    count++;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("文件导入失败！");
            } finally {
                try {
                    file.getInputStream().close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            builder.append("成功：[" + count + "]");
        }

        return builder.toString();
    }

    private void saveItemIm(AssetsInfo assetsInfoIm) {

        if (assetsInfoIm.getAssetName() == null) {
            return;
        }
        //查询资产信息是否有该资产
        QueryWrapper one1 = new QueryWrapper();
        one1.eq("asset_name", assetsInfoIm.getAssetName());
        AssetsInfo assetsInfo = assetsInfoService.getOne(one1);
        if (assetsInfo == null) {
            assetsInfo = new AssetsInfo();
            assetsInfo.setAssetName(assetsInfoIm.getAssetName());
            assetsInfo.setSpec(assetsInfoIm.getSpec());
            assetsInfo.setOwner(assetsInfoIm.getOwner());
            assetsInfo.setRemark(assetsInfoIm.getRemark());
            assetsInfo.setCompany(assetsInfoIm.getCompany());
            //设备分组、设备分类
            assetsInfo.setGroupName(assetsInfoIm.getGroupName());
            assetsInfo.setCategory(assetsInfoIm.getCategory());
            assetsInfoService.save(assetsInfo);
        }
        //先构建遗失数量
        if (assetsInfoIm.getLoseNum() != null) {
            for (int i = 0; i < assetsInfoIm.getLoseNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("遗失");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(0);
                assetsItem.setStoreUseNum(0);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);
            }

        }

        //先构建遗失数量
        if (assetsInfoIm.getExpendNum() != null) {
            for (int i = 0; i < assetsInfoIm.getExpendNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("消耗");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(0);
                assetsItem.setStoreUseNum(0);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);
            }

        }
        //构建损坏数量
        if (assetsInfoIm.getBadNum() != null) {
            for (int i = 0; i < assetsInfoIm.getBadNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("损坏");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(1);
                assetsItem.setStoreUseNum(0);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);
            }
        }
        /**
         * 构建仓库可用数量
         */
        if (assetsInfoIm.getStoreUseNum() != null) {
            for (int i = 0; i < assetsInfoIm.getStoreUseNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("正常");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(1);
                assetsItem.setStoreUseNum(1);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);
            }

        }
        //外借由于没办法生成申领单，先按照正常的处理，状态为外借
        if (assetsInfoIm.getApplyNum() != null) {
            for (int i = 0; i < assetsInfoIm.getApplyNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("正常");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(1);
                assetsItem.setStoreUseNum(1);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);

            }
        }
        //构建返厂数量
        if (assetsInfoIm.getReturnNum() != null) {
            for (int i = 0; i < assetsInfoIm.getReturnNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("返厂维修");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(0);
                assetsItem.setStoreUseNum(0);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);
            }
        }
        //构建报废数量
        if (assetsInfoIm.getAbandonedNum() != null) {
            for (int i = 0; i < assetsInfoIm.getAbandonedNum(); i++) {
                AssetsItem assetsItem = new AssetsItem();
                assetsItem.setAssetName(assetsInfo.getAssetName());
                assetsItem.setStatus("报废");
                assetsItem.setApplyStatus(1);
                assetsItem.setNum(1);
                assetsItem.setStoreNum(0);
                assetsItem.setStoreUseNum(0);
                assetsItem.setId(null);
                this.save(assetsItem);
                String assetCoding = String.format("%06d", assetsItem.getId());
                assetsItem.setAssetCoding(assetCoding);
                this.updateById(assetsItem);
            }
        }

        assetsJob.startWron();


    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void bingCatagery(AssetsItem assetsItem) {
        //根据iD分组
        String[] ids = StringUtils.split(assetsItem.getIds(), ",");
        //判断分类是否为空
        if (StringUtils.isEmpty(assetsItem.getCategoryName())) {
            //更新资产分类为空
            UpdateWrapper wrapper = new UpdateWrapper();
            wrapper.in("id", ids);
            wrapper.set("category", null);
            wrapper.set("category_name", null);
            this.update(null, wrapper);

        } else {
            Integer category = assetsItem.getCategory();
            QueryWrapper qw = new QueryWrapper();
            qw.eq("category_name", assetsItem.getCategoryName());
            AssetsCategory assetsCategory = assetsCategoryService.getOne(qw);
            if (assetsCategory == null) {
                //新增分类
                assetsCategory = new AssetsCategory();
                assetsCategory.setCategoryName(category + "");
                assetsCategoryService.save(assetsCategory);
            }
            //更新资产分类为空
            UpdateWrapper wrapper = new UpdateWrapper();
            wrapper.in("id", ids);
            wrapper.set("category", assetsCategory.getId());
            wrapper.set("category_name", assetsCategory.getCategoryName());
            this.update(null, wrapper);
        }


    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void bingGroup(AssetsItem assetsItem) {
        String[] ids = StringUtils.split(assetsItem.getIds(), ",");
        //判断组别是否为空
        if (StringUtils.isEmpty(assetsItem.getGroupName())) {
            //更新资产分类为空
            UpdateWrapper wrapper = new UpdateWrapper();
            wrapper.in("id", ids);
            wrapper.set("`group`", null);
            wrapper.set("group_name", null);
            this.update(null, wrapper);
        } else {
            String groupName = assetsItem.getGroupName();
            QueryWrapper qw = new QueryWrapper();
            qw.eq("group_name", groupName);
            AssetsGroup assetsGroup = assetsGroupService.getOne(qw);
            if (assetsGroup == null) {
                //新增组别
                assetsGroup = new AssetsGroup();
                assetsGroup.setGroupName(groupName);
                assetsGroupService.save(assetsGroup);
            }
            //更新资产分类为空
            UpdateWrapper wrapper = new UpdateWrapper();
            wrapper.in("id", ids);
            wrapper.set("`group`", assetsGroup.getId());
            wrapper.set("group_name", assetsGroup.getGroupName());
            this.update(null, wrapper);

        }


    }

    @Override
    public AssetsItem queryById(String id) {

        //获取资产详情
        AssetsItem assetsItem = this.getById(id);
        //获取对应的归还单和申请单。
        if (assetsItem != null) {
            List<ApplyAndReturnItem> applyAndReturnItems = new ArrayList<>();
            QueryWrapper qw = new QueryWrapper();
            qw.eq("asset_coding", assetsItem.getAssetCoding());
            List<AssetsApplyItem> list = assetsApplyItemService.list(qw);
            for (AssetsApplyItem assetsApplyItem : list) {
                ApplyAndReturnItem applyAndReturnItem = new ApplyAndReturnItem();
                applyAndReturnItem.setAssetCoding(assetsApplyItem.getAssetCoding());
                applyAndReturnItem.setAssetName(assetsApplyItem.getAssetName());
                applyAndReturnItem.setOptionUserer(assetsApplyItem.getApplyUser());
                applyAndReturnItem.setCreateTime(assetsApplyItem.getCreateTime());
                applyAndReturnItem.setStatus(assetsApplyItem.getStatus());
                applyAndReturnItem.setType("领用单");
                applyAndReturnItems.add(applyAndReturnItem);
            }
            List<AssetsReturnItem> returnList = assetsReturnItemService.list(qw);
            for (AssetsReturnItem assetsReturnItem : returnList) {
                ApplyAndReturnItem applyAndReturnItem = new ApplyAndReturnItem();
                applyAndReturnItem.setAssetCoding(assetsReturnItem.getAssetCoding());
                applyAndReturnItem.setAssetName(assetsReturnItem.getAssetName());
                applyAndReturnItem.setOptionUserer(assetsReturnItem.getReturnUser());
                applyAndReturnItem.setCreateTime(assetsReturnItem.getCreateTime());
                applyAndReturnItem.setStatus(assetsReturnItem.getStatus());
                applyAndReturnItem.setType("归还单");
                applyAndReturnItems.add(applyAndReturnItem);
            }
            //根据创建时间排序
            applyAndReturnItems.sort(Comparator.comparing(ApplyAndReturnItem::getCreateTime).reversed());
            assetsItem.setApplyAndReturnItems(applyAndReturnItems);


            return assetsItem;

        }
        //

        return null;
    }

    @Override
    public AssetsItem queryByCode(String code) {
        //获取资产详情
        QueryWrapper queryWrapper = new QueryWrapper();
        //只提取数字

        queryWrapper.eq("asset_coding", code.substring(code.length() - 6));
        AssetsItem assetsItem = this.getOne(queryWrapper);
        //获取对应的归还单和申请单。
        if (assetsItem != null) {
            List<ApplyAndReturnItem> applyAndReturnItems = new ArrayList<>();
            QueryWrapper qw = new QueryWrapper();
            qw.eq("asset_coding", assetsItem.getAssetCoding());
            List<AssetsApplyItem> list = assetsApplyItemService.list(qw);
            for (AssetsApplyItem assetsApplyItem : list) {
                ApplyAndReturnItem applyAndReturnItem = new ApplyAndReturnItem();
                applyAndReturnItem.setAssetCoding(assetsApplyItem.getAssetCoding());
                applyAndReturnItem.setAssetName(assetsApplyItem.getAssetName());
                applyAndReturnItem.setOptionUserer(assetsApplyItem.getLender());
                applyAndReturnItem.setCreateTime(assetsApplyItem.getCreateTime());
                applyAndReturnItem.setStatus(assetsApplyItem.getStatus());
                applyAndReturnItem.setRemark(assetsApplyItem.getRemark());

                applyAndReturnItem.setType("领用单");
                applyAndReturnItems.add(applyAndReturnItem);
            }
            List<AssetsReturnItem> returnList = assetsReturnItemService.list(qw);
            for (AssetsReturnItem assetsReturnItem : returnList) {
                ApplyAndReturnItem applyAndReturnItem = new ApplyAndReturnItem();
                applyAndReturnItem.setAssetCoding(assetsReturnItem.getAssetCoding());
                applyAndReturnItem.setAssetName(assetsReturnItem.getAssetName());
                applyAndReturnItem.setOptionUserer(assetsReturnItem.getLender());
                applyAndReturnItem.setCreateTime(assetsReturnItem.getCreateTime());
                applyAndReturnItem.setStatus(assetsReturnItem.getStatus());
                applyAndReturnItem.setRemark(assetsReturnItem.getRemark());
                applyAndReturnItem.setType("归还单");
                applyAndReturnItems.add(applyAndReturnItem);
            }
            //根据创建时间排序
            applyAndReturnItems.sort(Comparator.comparing(ApplyAndReturnItem::getCreateTime).reversed());
            assetsItem.setApplyAndReturnItems(applyAndReturnItems);
            if (assetsItem.getCategory() != null) {
                AssetsCategory byId = assetsCategoryService.getById(assetsItem.getCategory());
                assetsItem.setAssetCoding(byId.getAlias() != null ? byId.getAlias() + assetsItem.getAssetCoding() : assetsItem.getAssetCoding());


            }
            return assetsItem;
        }
        //

        return null;
    }

    /**
     * 外借资产明细查询
     *
     * @param page
     * @param queryWrapper
     * @return
     */
    @Override
    public IPage<AssetsApplyDTO> queryPageListByApply(Page page, AssetsApplyDTO assetsItem) {

        return assetsItemMapper.queryPageListByApply(page, assetsItem);

    }

    @Override
    public ModelAndView exportXlsApply(AssetsApplyDTO assetsItem, Class<AssetsApplyDTO> clazz, String title) {

        // Step.1 组装查询条件
        Page<AssetsApplyDTO> page = new Page<AssetsApplyDTO>(1, 1000000);

        IPage<AssetsApplyDTO> assetsApplyDTOIPage = assetsItemMapper.queryPageListByApply(page, assetsItem);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<AssetsApplyDTO> exportList = assetsApplyDTOIPage.getRecords();
        // Step.3 AutoPoi 导出Excel
        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
        //此处设置的filename无效 ,前端会重更新设置一下
        mv.addObject(NormalExcelConstants.FILE_NAME, title);
        mv.addObject(NormalExcelConstants.CLASS, clazz);
        //update-begin--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置--------------------
        ExportParams exportParams = new ExportParams(title, "导出人:" + sysUser.getRealname(), title);
        // exportParams.setImageBasePath(jeecgBaseConfig.getPath().getUpload());
        //update-end--Author:liusq  Date:20210126 for：图片导出报错，ImageBasePath未设置----------------------
        mv.addObject(NormalExcelConstants.PARAMS, exportParams);
        mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
        return mv;
    }

    @Override
    public void editBatchStatus(AssetsItem assetsItem) {
        String[] ids = StringUtils.split(assetsItem.getIds(), ",");
        //判断组别是否为空
        if (assetsItem.getStatus() != null) {
            for (String id : ids) {
                AssetsItem assetsItem1 = this.getById(id);
                assetsItem1.setStatus(assetsItem.getStatus());
                this.updateById(assetsItem1);
            }
        }

    }

    /**
     * 批量备注编辑
     * @param assetsItem
     */

    @Override
    public void editBatchRemark(AssetsItem assetsItem) {

        this.updateById(assetsItem);
    }

    /**
     * 本地文件上传
     *
     * @param mf      文件
     * @param bizPath 自定义路径
     * @return
     */
    private String uploadLocal(MultipartFile mf, String bizPath) {
        //LOWCOD-2580 sys/common/upload接口存在任意文件上传漏洞
        if (oConvertUtils.isNotEmpty(bizPath) && (bizPath.contains("../") || bizPath.contains("..\\"))) {
            throw new JeecgBootException("上传目录bizPath，格式非法！");
        }
        try {
            String ctxPath = uploadpath;
            String fileName = null;
            File file = new File(ctxPath + File.separator + bizPath + File.separator);
            if (!file.exists()) {
                file.mkdirs();// 创建文件根目录
            }
            String orgName = mf.getOriginalFilename();// 获取文件名
            orgName = CommonUtils.getFileName(orgName);
            if (orgName.indexOf(".") != -1) {
                fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.indexOf("."));
            } else {
                fileName = orgName + "_" + System.currentTimeMillis();
            }
            String savePath = file.getPath() + File.separator + fileName;
            File savefile = new File(savePath);
            FileCopyUtils.copy(mf.getBytes(), savefile);
            String dbpath = null;
            if (oConvertUtils.isNotEmpty(bizPath)) {
                dbpath = bizPath + File.separator + fileName;
            } else {
                dbpath = fileName;
            }
            if (dbpath.contains("\\")) {
                dbpath = dbpath.replace("\\", "/");
            }
            return dbpath;
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return "";
    }

    /**
     * 自动更新数量
     */
    public void autoNum() {
        //更新分类数量
        //更新编组数量
        //更正装备数量


    }
}
